import { Random, mock } from 'mockjs'
import { resultSuccess, doCustomTimes, resultPage } from '../_util'

const tableList = (pageSize: number) => {
  const result: any[] = []
  doCustomTimes(pageSize, () => {
    result.push({
      id: '@integer(10,999999)',
      beginTime: '@datetime',
      endTime: '@datetime',
      address: '@city()',
      name: '@cname()',
      avatar: Random.image('400x400', Random.color(), Random.color(), Random.first()),
      tel: '1' + '@integer(2,9)' + mock(/\d{9}/),
      date: '@date(\'yyyy-MM-dd\')',
      time: '@time(\'HH:mm\')',
      'no|100000-10000000': 100000,
      'status|1': [true, false],
    })
  })
  return result
}

export default [
  // 表格数据列表
  {
    url: '/api/table/list',
    timeout: 1000,
    method: 'get',
    response: ({ query }) => {
      const { currentPage = 1, pageSize = 10 } = query
      const list = tableList(Number(pageSize))

      return resultSuccess({
        result: {
          ...resultPage({
            currentPage: Number(currentPage),
            pageSize: Number(pageSize),
          }),
          list,
          total: 60
        }
      })
    },
  },
]
